﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace Common.EncryptDecrypt
{
    /// <summary>
    /// Md5算法
    /// </summary>
    public static class Md5
    {
        /// <summary>
        /// 计算Md5值
        /// </summary>
        /// <param name="bytes"></param>
        /// <returns></returns>
        public static string ByteToMd5(byte[] bytes) 
        {
            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
            string result = BitConverter.ToString(md5.ComputeHash(bytes));
            result = result.Replace("-", "");
            return result;
        }
        /// <summary>
        /// 计算Md5值
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string StrToMd5(string str) 
        {            
            byte[] bytes = Encoding.UTF8.GetBytes(str);
            return ByteToMd5(bytes);
        }
    }
}
